package com.example.MyRESTAssured.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class JSONController {


    /**
     * 使用groovy和jsonpath查询和获取json中的属性值
     * @return
     */
    @RequestMapping(value = "/store",method = RequestMethod.GET )
    @ResponseBody
    public String validateJSONGroovyGetRequest(){

        String res="{  \n" +
                "   \"store\":{  \n" +
                "      \"book\":[  \n" +
                "         {  \n" +
                "            \"author\":\"Nigel Rees\",\n" +
                "            \"category\":\"reference\",\n" +
                "            \"price\":8.95,\n" +
                "            \"title\":\"Sayings of the Century\"\n" +
                "         },\n" +
                "         {  \n" +
                "            \"author\":\"Evelyn Waugh\",\n" +
                "            \"category\":\"fiction\",\n" +
                "            \"price\":12.99,\n" +
                "            \"title\":\"Sword of Honour\"\n" +
                "         },\n" +
                "         {  \n" +
                "            \"author\":\"Herman Melville\",\n" +
                "            \"category\":\"fiction\",\n" +
                "            \"isbn\":\"0-553-21311-3\",\n" +
                "            \"price\":8.99,\n" +
                "            \"title\":\"Moby Dick\"\n" +
                "         },\n" +
                "         {  \n" +
                "            \"author\":\"J. R. R. Tolkien\",\n" +
                "            \"category\":\"fiction\",\n" +
                "            \"isbn\":\"0-395-19395-8\",\n" +
                "            \"price\":22.99,\n" +
                "            \"title\":\"The Lord of the Rings\"\n" +
                "         }\n" +
                "      ]\n" +
                "   }\n" +
                "}";
        return res;
    }

    /**
     * 反序列化json数据成范型list
     * @return
     */
    @RequestMapping(value = "/products",method = RequestMethod.GET )
    @ResponseBody
    public String validateDeserializationGetRequest(){

        String res="[\n" +
                "          {\n" +
                "              \"id\": 2,\n" +
                "              \"name\": \"An ice sculpture\",\n" +
                "              \"price\": 12.50,\n" +
                "              \"tags\": [\"cold\", \"ice\"],\n" +
                "              \"dimensions\": {\n" +
                "                  \"length\": 7.0,\n" +
                "                  \"width\": 12.0,\n" +
                "                  \"height\": 9.5\n" +
                "              },\n" +
                "              \"warehouseLocation\": {\n" +
                "                  \"latitude\": -78.75,\n" +
                "                  \"longitude\": 20.4\n" +
                "              }\n" +
                "          },\n" +
                "          {\n" +
                "              \"id\": 3,\n" +
                "              \"name\": \"A blue mouse\",\n" +
                "              \"price\": 25.50,\n" +
                "                  \"dimensions\": {\n" +
                "                  \"length\": 3.1,\n" +
                "                  \"width\": 1.0,\n" +
                "                  \"height\": 1.0\n" +
                "              },\n" +
                "              \"warehouseLocation\": {\n" +
                "                  \"latitude\": 54.4,\n" +
                "                  \"longitude\": -32.7\n" +
                "              }\n" +
                "          }\n" +
                "      ]";
        return res;
    }


}
